// 文章接口模块
import { request } from '../utils/request.js'

// 获取频道文章列表
export const getArticles = params => request({
  method: 'GET',
  url: '/v1_0/articles',
  params
})

/**
 * 获取文章详情
 */
export const getArticleById = articleId => request({
  method: 'GET',
  url: `/v1_0/articles/${articleId}`
})

/**
 * 收藏
 * @params targetId 文章id
 */
export const addCollect = targetId => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target: targetId
    }
  })
}

/**
 * 取消收藏
 * @params targetId 文章id
 */
export const deleteCollect = targetId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/collections/${targetId}`
  })
}

/**
 * 点赞文章
 */
export const addLike = targetId => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: targetId
    }
  })
}

/**
 * 取消点赞文章
 */
export const deleteLike = targetId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${targetId}`
  })
}
